app.controller('vipMessagePwdverifyPageCtrl',function($scope,$state,$stateParams,$http,$myconfig,$interval,$ionicConfig){
    //接收上衣一面传送的参数
    $scope.newPwd = {
        mobile:$stateParams.phoNo
    };
    // console.log($scope.newPhon);

    $scope.seBtn = true;
    //定义倒计时
    $scope.secend = 60;


    //向后台获取验证码
    $scope.getCode = function(code){
        $http.post($myconfig.api.base_host + '/users/get_code',{
            "mobile":code,
	        "code_type":"change_password"
        }).then(function(res){
            if(res.data.success){
                $scope.seBtn = false;
                $interval(function(){
                    $scope.secend--
                    if($scope.secend == 0){
                        $scope.seBtn = true;
                        $scope.secend = 60;
                    }
                },1000,60);
             }else{
                //  如果没获取到验证码，则向页面抛出后台返回错误信息
                 $scope.err = res.data.data;
             }
        });
    };

    //校验验证码输入是否正确，如果正确则进入下一一面，不正确则向页面抛出错误信息
    $scope.enterPwd = function(){
        $http.post($myconfig.api.base_host + '/users/verify',{
            "code":$scope.newPwd.codeType,
            "mobile":$scope.newPwd.mobile,
            "code_type":"change_password"
        }).then(function(res){
            if(res.data.success){
                 $state.go('app.vip_message_newpwd',{NewPwd:JSON.stringify($scope.newPwd)});
            }else{
                $scope.err = res.data.data;
            }
        });
    };


    //如果接收到的参数位真的话，则执行获取验证码操作
    // if($scope.newPwd.mobile){
    //     $scope.getCode($scope.newPwd.mobile);
    // };
    $scope.$on('$ionicView.enter', function(){

        $ionicConfig.views.swipeBackEnabled(false);

    });

});
